package com.bcu.cn.onlineexamsystem.teacherhomemanage.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface TeacherHomeMapper {
    
    /**
     * 根据用户ID查询用户真实姓名
     */
    @Select("SELECT real_name FROM users WHERE user_id = #{userId}")
    String getRealNameByUserId(@Param("userId") String userId);
    
    /**
     * 查询教师创建的考试总数
     */
    @Select("SELECT COUNT(*) FROM exams WHERE teacher_id = #{teacherId}")
    Integer getTotalExamsCount(@Param("teacherId") String teacherId);
    
    /**
     * 查询题库题目总数
     */
    @Select("SELECT COUNT(*) FROM questions")
    Integer getQuestionCount();
    
    /**
     * 查询待批改考试数量（待批改的学生考试记录数）
     */
    @Select("SELECT COUNT(*) FROM student_exams se " +
            "JOIN exams e ON se.exam_id = e.exam_id " +
            "WHERE e.teacher_id = #{teacherId} " +
            "AND se.status = 2 " +
            "AND se.total_score IS NULL")
    Integer getPendingExamsCount(@Param("teacherId") String teacherId);
    
    /**
     * 查询教师最近创建的考试名称
     */
    @Select("SELECT exam_name FROM exams WHERE teacher_id = #{teacherId} ORDER BY start_time DESC LIMIT 1")
    String getLatestExamName(@Param("teacherId") String teacherId);
} 